Skip to content

Conversation

iabdalkader
Copy link

@iabdalkader iabdalkader commented Oct 1, 2025

The _static_thread_data struct contains int64_t members that require 8-byte alignment. When placed in a 4-byte aligned section, it causes the linker to insert padding, which in turn causes __static_thread_data_list_start to point to the padding not to the first iterable.

GNU ld automatically aligns output sections based on the strictest alignment requirement of input sections, so moving __static_thread_data_list to its own section fixes the problem.

@iabdalkader iabdalkader force-pushed the fix_thread_section_alignment branch from 6588cbd to ccc56ce Compare October 1, 2025 13:36
@iabdalkader iabdalkader changed the title Fix thread section alignment. core: Fix thread section alignment. Oct 1, 2025
@iabdalkader iabdalkader force-pushed the fix_thread_section_alignment branch 2 times, most recently from 8bdc53e to 1bab673 Compare October 1, 2025 14:25
The _static_thread_data struct contains int64_t members that require 8-byte
alignment. When placed in a 4-byte aligned section, it causes the linker to
insert padding, which in turn causes __static_thread_data_list_start to point
to the padding not to the first iterable.

GNU ld automatically aligns output sections based on the strictest alignment
requirement of input sections, so moving __static_thread_data_list to its own
section fixes the problem.

Signed-off-by: iabdalkader <[email protected]>
According to Zephyr documentation, k_thread_create() both initializes
and starts the thread. The second loop that was calling k_thread_start()
on each static thread was redundant.

Signed-off-by: iabdalkader <[email protected]>
@iabdalkader iabdalkader force-pushed the fix_thread_section_alignment branch from 1bab673 to 9416d15 Compare October 15, 2025 12:50
Copy link

@pillo79 pillo79 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. With the following change, this PR will also fix the Region ... overlaps with ... issue AFAICS.


.static_thread_data_area : {
__static_thread_data_list_start = .;
KEEP(*(SORT_BY_NAME(.__static_thread_data.static.*)));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
KEEP(*(SORT_BY_NAME(.__static_thread_data.static.*)));
KEEP(*(.static_thread_data_area SORT_BY_NAME(.__static_thread_data.*)));


.static_thread_data_area : {
__static_thread_data_list_start = .;
KEEP(*(SORT_BY_NAME(.__static_thread_data.static.*)));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
KEEP(*(SORT_BY_NAME(.__static_thread_data.static.*)));
KEEP(*(.static_thread_data_area SORT_BY_NAME(.__static_thread_data.*)));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants